<?php

connectToDatabase();
$category = $_SESSION['category'];
$query = "SELECT o.city, o.stateName, o.organizationName, io.* FROM opportunity io, ORGANIZATION o WHERE io.organizationID = o.organizationID AND io.categories LIKE '%$category%' ORDER BY io.dateAdded DESC";

$result = mysql_query($query);
if (!$result
   )die("Could not complete query... " . mysql_error());

$numRows = mysql_num_rows($result);
echo "<table width='100%' cellspacing=0><tr><td width='10%'></td><td width='15%'><b>Date Added</b> (Y-M-D)</td><td><b>Location</b></td><td><b>Position</b></td><td><b>Company</b></td><td width='10%'><b>Positions Available</b></td><td><b>Pay Rate</b></td><td><b>Semester</b></td></tr>";
echo "<tr><td colspan=8><hr /></td></tr>";
for ($x = 0; $x < $numRows; $x++) {
   $row = mysql_fetch_assoc($result);
   $id = $row['opportunityID'];
   $city = $row['city'];
   $state = strtoupper($row['stateName']);
   $title = $row['title'];
   $name = $row['organizationName'];
   $numPositions = $row['numPositionsAvailable'];
   $payRate = $row['payRate'];
   $semester = $row['semester'];
   $dateAdded = $row['dateAdded'];
   $dateAdded = substr($dateAdded, 0, 10);
   if ($x % 2 == 0) {
      echo "<tr>";
   } else {
      echo "<tr bgcolor='#FBFBFB'>";
   }
   echo "<td align='center' valign='middle'><br /><form action='index.php' method='get'><input type='hidden' name='internship_id' value='$id'><input type='submit' value='View' class='submit' name='view_info' /></form></td>";
   echo "<td>$dateAdded</td>";
   echo "<td>$city, " . $state . "</td>";
   echo "<td>$title</td>";
   echo "<td>$name</td>";
   echo "<td>$numPositions</td>";
   echo "<td>$payRate</td>";
   echo "<td>$semester</td>";
   echo "</tr>";
}
echo "</table>";
?>
